﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Biz_Dal.Dal;

namespace Biz_Dal.Biz
{
    public class BizDonDatHang
    {
        private int idDDH;

        public int Id
        {
            get { return idDDH; }
            set { idDDH = value; }
        }

        private DateTime ngayDat;

        public DateTime NgayDat
        {
            get { return ngayDat; }
            set { ngayDat = value; }
        }

        private DateTime ngayGiao;

        public DateTime NgayGiao
        {
            get { return ngayGiao; }
            set { ngayGiao = value; }
        }

        private double tongTien;

        public double TongTien
        {
            get
            {
                //foreach (BizCTDonDatHang ct in ctDonDatHangs)
                //{
                //    tongTien += ct.ThanhTien;
                //}
                return tongTien;
            }
            set { tongTien = value; }
        }

        private BizTrangThaiDH trangThaiDH;

        public BizTrangThaiDH TrangThaiDH
        {
            get { return trangThaiDH; }
            set { trangThaiDH = value; }
        }

        public string TenTrangThai
        {
            get { return TrangThaiDH == null ? string.Empty : TrangThaiDH.TenTTDH; }
        }

        private BizKhachHang khachHang;

        public BizKhachHang KhachHang
        {
            get { return khachHang; }
            set { khachHang = value; }
        }

        public string TenKhachHang
        {
            get { return KhachHang == null ? string.Empty : KhachHang.hoTen; }
        }

        public BizDonDatHang(int _id)
        {
            Id = _id;
        }

        private int _idKH;

        public int IdKH
        {
            get { return _idKH; }
            set { _idKH = value; }
        }

        private int _idTrangThai;

        public int IdTrangThai
        {
            get { return _idTrangThai; }
            set { _idTrangThai = value; }
        }

        public BizDonDatHang(int _id, DateTime _ngayDat, DateTime _ngayGiao, double _tongTien, BizKhachHang _khachHang, int _idTrangThai)
        {
            Id = _id;
            NgayDat = _ngayDat;
            ngayGiao = _ngayGiao;
            TongTien = _tongTien;
            KhachHang = _khachHang;
            this._idTrangThai = _idTrangThai;
        }

        public BizDonDatHang(int _id, DateTime _ngayDat, DateTime _ngayGiao, double _tongTien, int _idkhachHang, int _idTrangThai)
        {
            Id = _id;
            NgayDat = _ngayDat;
            ngayGiao = _ngayGiao;
            TongTien = _tongTien;
            IdKH = _idkhachHang;
            this._idTrangThai = _idTrangThai;
        }

        public BizDonDatHang()
        { 
        
        }

        public void Insert()
        {
            Id = DalDonDatHang.Insert(this);
        }

        //lấy id mới
        public static int IdMaxDDH()
        {
            try
            {
                return DalDonDatHang.IdMaxDDH();
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizDonDatHang> getDDHByIDKhachHang(int idKHg)
        {
            try
            {
                return DalDonDatHang.getDDHByIDKhachHang(idKHg);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }
    }
}
